Allow Sparkline to be of any height#6171
Conversation
willmcgugan
left a comment
There was a problem hiding this comment.
Nice.
Can I request a snapshot test?
See test_snapshots.py for examples. Can be very simple, just a single sparkline is all that is needed.
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the Sparkline widget to support multi-line rendering at any height, not just a single line. The implementation adds a height parameter that controls how many terminal lines the sparkline uses, with taller sparklines providing more granular vertical resolution for data visualization.
Key Changes:
- Added
heightparameter toSparklinerenderable with appropriate default ofNone(defaulting to 1) - Updated rendering logic to distribute bar segments across multiple lines
- Modified edge case handling (empty data, single datapoint) to respect the height parameter
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/textual/renderables/sparkline.py | Core implementation: added height parameter, updated rendering algorithm to distribute bar segments across multiple lines, and fixed edge cases |
| src/textual/widgets/_sparkline.py | Widget integration: passes widget height to the sparkline renderable |
| tests/renderables/test_sparkline.py | Test coverage: added parametrized tests for heights 1, 2, and 3 |
| CHANGELOG.md | Documentation: added changelog entry for the new feature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@willmcgugan Added snapshot test, hope I did it right 🙏 |
69e5db0 to
a89e862
Compare
|
@willmcgugan Any chance you can take a look? |
|
Thanks |
Make
Sparklinebe able to use not only 1 as a height value.Demo app:
Result:

Please review the following checklist.